import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.snakegame.databinding.ItemLeaderboardBinding
import com.example.snakegame.model.Score

class LeaderboardAdapter(private val scores: List<Score>) : 
    RecyclerView.Adapter<LeaderboardAdapter.ViewHolder>() {

    class ViewHolder(private val binding: ItemLeaderboardBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(score: Score, position: Int) {
            binding.apply {
                rankText.text = "${position + 1}."
                usernameText.text = score.username
                scoreText.text = score.score.toString()
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemLeaderboardBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(scores[position], position)
    }

    override fun getItemCount() = scores.size
} 